#include "dynamicArray.h"
#include <cstdlib>
using namespace std;

dynamicArray::dynamicArray()
{
	m_height = SIZE;
	m_width = SIZE;
	m_writeX = 0;
	m_writeY = 0;
	m_data = NULL;
}

dynamicArray::dynamicArray(int x, int y)
{
	m_height = y;
	m_width = x;
	m_writeX = 0;
	m_writeY = 0;
	m_data = NULL;
}

dynamicArray::~dynamicArray()
{
	delete [] m_data;
	m_data = NULL;
}

int dynamicArray::add(char c)
{
	if (m_data == NULL)
	{
		m_data = new char *[m_width];
		for (int i = 0; i < m_width; i++)
		{
			*(m_data + i) = new char [m_height];
		}
	}
	if (m_writeX >= m_width)
	{
		m_writeX = 0;
		m_writeY += 1;
	}
	if (m_writeY >= m_height)
	{
		m_writeX = 0;
		m_writeY = 0;
	}
		////Find more memory and then copy over the array.
		//char* tempArray = new char[m_size+SIZE];
		//for(int i = 0; i < m_size; i++)
		//{
		//	tempArray[i] = m_data[i];
		//}
		//delete [] m_data;
		//m_data = new char[m_size+SIZE];
		//for(int i = 0; i < m_size; i++)
		//{
		//	m_data[i] = tempArray[i];
		//}
		//delete [] tempArray;
		//tempArray = NULL;
		//m_size += SIZE;
	m_data[m_writeY][m_writeX] = c;
	m_writeX++;
	return 0;
}

int dynamicArray::add(char c, int numX, int numY)
{
	if (m_data = NULL)
	{
		m_data = new char *[m_width];
		for (int i = 0; i < m_width; i++)
		{
			*(m_data + i) = new char [m_height];
		}
	}
	if (numX >= m_width || numX < 0)
	{
		return -1;	//Outside of x
	}
	if (numY >= m_height || numY < 0)
	{
		return -2;	//Outside of y
	}
		////Find more memory and then copy over the array.
		//char* tempArray = new char[m_size+SIZE];
		//for(int i = 0; i < m_size; i++)
		//{
		//	tempArray[i] = m_data[i];
		//}
		//delete [] m_data;
		//m_data = new char[m_size+SIZE];
		//for(int i = 0; i < m_size; i++)
		//{
		//	m_data[i] = tempArray[i];
		//}
		//delete [] tempArray;
		//tempArray = NULL;
		//m_size += SIZE;
	m_data[m_writeY][m_writeX] = c;
}

char dynamicArray::get(int numX, int numY)
{
	return m_data[numY][numX];
}

int dynamicArray::size()
{
	return m_width * m_height;
}

int dynamicArray::width()
{
	return m_width;
}

int dynamicArray::height()
{
	return m_height;
}